//
//  WorkReportViewController.m
//  Utils
//
//  Created by enghou on 2018/6/4.
//  Copyright © 2018年 xyxorigation. All rights reserved.
//

#import "WorkReportViewController.h"
#import "WorkReportSearchViewController.h"
#import "AddReportViewController.h"
#import "WorkReportItemModel.h"
@interface WorkReportViewController ()

@end

@implementation WorkReportViewController

-(NSDictionary *)param{
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setObject:[NSString stringWithFormat:@"%li",self.page] forKey:@"page"];
    [param setObject:@"10" forKey:@"rows"];
    NSString *orgid = [self orgId];
    if (orgid) {
        [param setObject:orgid forKey:@"workDiaryVo.orgId"];
    }
    if ([self.choosenParam isKindOfClass:[NSDictionary class]]) {
        [param addEntriesFromDictionary:self.choosenParam];
    }
    
    return param;
}



-(void)searchAction{
    WorkReportSearchViewController *search = [[WorkReportSearchViewController alloc]init];
    search.title = @"工作日志查询";
    search.delegate = self;
    [self push:search];
}

-(instancetype)init{
    self = [super init];
    if (self) {
        self.path = @"/mobile/comprehensiveGovernance/workDiary/findWorkDiaryPage.action";
        self.cellClass = @"WorkReportCell";
        self.modelClsName = @"WorkReportItemModel";
    }
    return self;
}

#pragma mark - 收到查询参数要做的事情
-(void)fetchParameter:(NSDictionary *)param{
    if (param) {
        self.choosenParam = param;
    }
    [self beginRefresh];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.source.count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 10;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *footer = [[UIView alloc]init];
    footer.backgroundColor = [UIColor defaultBackgroundColor];
    return footer;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    WorkReportItemModel *model = [self.source objectAtIndex:indexPath.section];
    AddReportViewController *add = [[AddReportViewController alloc]init];
    if ([model.code isEqualToString:@"10"]) {
        add.type = 0;
    }else if ([model.code isEqualToString:@"30"]){
        add.type = 1;
    }else if ([model.code isEqualToString:@"50"]){
        add.type = 2;
    }else if ([model.code isEqualToString:@"70"]){
        add.type = 3;
    }
    add.title = @"工作日志详情";
    add.ids = model.ids;
    [self push:add];
}

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([cell respondsToSelector:@selector(setModel:)]) {
        [cell performSelector:@selector(setModel:) withObject:self.source[indexPath.section]];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter]postNotificationName:@"Refresh_WorkDaily" object:nil];
}

-(void)addTextReport{
    AddReportViewController *add = [[AddReportViewController alloc]init];
    add.type = 0;
    add.title = @"工作日志新增";
    [self push:add];
}

-(void)addSoundReport{
    AddReportViewController *add = [[AddReportViewController alloc]init];
    add.type = 1;
    add.title = @"工作日志新增";
    [self push:add];
}

-(void)addMovReport{
    AddReportViewController *add = [[AddReportViewController alloc]init];
    add.type = 2;
    add.title = @"工作日志新增";
    [self push:add];
}

-(void)addPhotoReport{
    AddReportViewController *add = [[AddReportViewController alloc]init];
    add.type = 3;
    add.title = @"工作日志新增";
    [self push:add];
}

-(void)addAction{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *text = [UIAlertAction actionWithTitle:@"文字" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self addTextReport];
    }];
    [alert addAction:text];
    UIAlertAction *sound = [UIAlertAction actionWithTitle:@"录音" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self addSoundReport];
    }];
    [alert addAction:sound];
    UIAlertAction *mov = [UIAlertAction actionWithTitle:@"视频" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self addMovReport];
    }];
    [alert addAction:mov];
    UIAlertAction *photo = [UIAlertAction actionWithTitle:@"拍照或从手机相册选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self addPhotoReport];
    }];
    [alert addAction:photo];
    
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alert addAction:cancel];
    
    [self presentViewController:alert animated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)titleField:(id)sender {
}

- (IBAction)workerNameField:(id)sender {
}

- (IBAction)beginField:(id)sender {
}
@end
